home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume21 / cloops / part03 < prev    next >
Encoding:
Text File  |  1991-07-25  |  30.1 KB  |  723 lines

  1. Newsgroups: comp.sources.misc
  2. From: Martin Fouts <fouts@clipper.ingr.com>
  3. Subject:  v21i038:  cloops - Livermore Loops in C, Part03/03
  4. Message-ID: <1991Jul25.020740.28375@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 66bbb34c53801c38f1ef1b86799174b7
  6. Date: Thu, 25 Jul 1991 02:07:40 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Martin Fouts <fouts@clipper.ingr.com>
  10. Posting-number: Volume 21, Issue 38
  11. Archive-name: cloops/part03
  12. Environment: Cray2, Alliant Convex Amdahl, Sun, SGI  
  13.  
  14. -----     cut here for Part03
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 3 (of 3)."
  22. # Contents:  cloops.tex
  23. # Wrapped by fouts@bozeman on Sun Jul 21 18:23:21 1991
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'cloops.tex' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'cloops.tex'\"
  27. else
  28. echo shar: Extracting \"'cloops.tex'\" \(28304 characters\)
  29. sed "s/^X//" >'cloops.tex' <<'END_OF_FILE'
  30. X% C-Loops
  31. X%
  32. X% A Paper Describing the C version of the Livermore Loops
  33. X% Copyright (C) 1991 Martin Fouts
  34. X%
  35. X% This program is free software; you can redistribute it and/or modify
  36. X% it under the terms of the GNU General Public License as published by
  37. X% the Free Software Foundation; either version 1, or (at your option)
  38. X% any later version.
  39. X%
  40. X% This program is distributed in the hope that it will be useful,
  41. X% but WITHOUT ANY WARRANTY; without even the implied warranty of
  42. X% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  43. X% GNU General Public License for more details.
  44. X%
  45. X% You should have received a copy of the GNU General Public License
  46. X% along with this program; if not, write to the Free Software
  47. X% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  48. X%
  49. X
  50. X\documentstyle[12pt,twoside,fleqn,openbib]{article}
  51. X\pagestyle{myheadings}
  52. X\markboth{DRAFT of \today}{DRAFT of \today}
  53. X
  54. X\title{ The Livermore Loops in C
  55. X\\ DRAFT of \today }
  56. X
  57. X\author{
  58. XMartin Fouts \\
  59. XMathematician \\
  60. XNAS Systems Development Branch \\
  61. XNASA Ames Research Center}
  62. X
  63. X
  64. X\begin{document}
  65. X\maketitle
  66. X%\tableofcontents
  67. X%\vfill
  68. X%\pagebreak
  69. X\markboth{DRAFT of \today}{DRAFT of \today}
  70. X
  71. X\begin{abstract}
  72. X
  73. XThe Livermore Loops were transliterated from Fortran into C.  The
  74. Xresulting program was run on several machines which support both a C
  75. Xand Fortran compiler.  The effort taken in porting the loops is
  76. Xdiscussed, and the results are presented.  Some of the more
  77. Xinteresting results are analyzed. Problems which arise from
  78. Xusing the Loops as a benchmark suite are discussed. Some conclusions
  79. Xabout numerical computation in C are drawn.
  80. X
  81. X\end{abstract}
  82. X
  83. X\section{Background}
  84. X
  85. XNumerical calculations, especially those involving vector operations
  86. Xhave long been the territory of Fortran and it is widely accepted that
  87. Xno other high level language offers the same opportunity for compiler
  88. Xoptimization of source code.
  89. X
  90. XThe Livermore Loops\cite{McMahon86} are widely used as a benchmark of
  91. Xnumerical intensive calculation in Fortran and results are available
  92. Xfor a wide range of machines.  The loops were transliterated from
  93. XFortran into C and results were gathered for several machines.  On
  94. Xall machines the C compiler produces faster overall performance.
  95. XBoth languages calculated the same results.
  96. X
  97. XIn performing the conversion, some difficulties using the Livermore
  98. XLoops as a benchmark suite were uncovered.  They include the ease with
  99. Xwhich some compilers optimize away timing loops and the lack of
  100. Xsensitivity in the validation routines.  These difficulties are
  101. Xdiscussed in section 3.
  102. X
  103. XSome semantic differences between C and Fortran were uncovered which
  104. Xhave an effect on the precision of the results generated by the
  105. Xprogram on certain machines.  These differences are discussed in
  106. Xsection 3.
  107. X
  108. XThis experiment makes an interesting comment on the state of
  109. Xoptimizing compilers, the ability to write Fortran in any language,
  110. Xand the utility of the Livermore Loops as a vector benchmark.
  111. X
  112. XFor the purpose of this paper, Fortran refers to the Fortran language
  113. Xas described in the Fortran-77 standard\cite{ANSI77} and C refers to
  114. Xthe programming language as described in \cite{Kern78}.  References to
  115. Xspecific dialects will be labeled as such.
  116. X
  117. X\section{Overview of Transliteration}
  118. X
  119. XIn converting the Livermore Loops from Fortran to C, the major goal
  120. Xwas to  preserve the original Fortran semantics.  Some changes were
  121. Xnecessary, including:
  122. X
  123. X\begin{itemize}
  124. X
  125. X\item The routine \tt SPACE \rm was deleted.  Since the pointer
  126. Xassignment isn't used in the Fortran implementation, this has no
  127. Xeffect on the final results.
  128. X
  129. X\item The variable \tt lp \rm which controls the number of passes was
  130. Xmade an input parameter.  The default is 100 passes.  When the default
  131. Xis used, standard results are obtained.
  132. X
  133. X\item In kernel 15, arithmetic if statements were modified to
  134. Xif-then-else forms.
  135. X
  136. X\item All occurrences of the form \tt x**2 \rm were replaced by \tt
  137. Xx*x.
  138. X
  139. X\item \tt REPORT \rm was truncated.  Only the flop rates and averages
  140. Xare reported.  Since the C version is only intended as a comparison to
  141. XFortran on the same machine, the analysis portion is not needed.
  142. X
  143. X\item \tt SIGNAL \rm was reimplemented as several separate routines to
  144. Xwork around differences in C and Fortran parameter passing.  Further,
  145. X\tt VECTOR \rm was modified to call \tt lsignalN \rm for each array,
  146. Xsince C has no equivalent to a \tt COMMON \rm block.  \tt SIGNAL \rm
  147. Xwas renamed to \tt lsignalN \rm where \tt N \rm is replaced by 0, 1,
  148. X2, or 3 to represent the number of dimensions in the array being
  149. Xinitialized.  The separate routines are not strictly needed, but
  150. Xclarify the intent of the code.
  151. X
  152. XSince \tt SIGNAL \rm is not part of the measured code, this has no
  153. Xeffect on the reported performance.
  154. X
  155. X\item The number generation routine used by \tt SIGNAL \rm was
  156. Xcarefully reimplemented to duplicate Fortran numeric semantics.
  157. X
  158. X\item \tt SUMO \rm was reimplemented as \tt sumo, sumo2, \rm and \tt
  159. Xsumo3 \rm, depending on the number of dimensions in the array being
  160. Xinitialized.  As with signal, this was done for clarity and is in code
  161. Xwhich is not part of that being measured.
  162. X
  163. X\item A command line option was added allowing only specified loops to
  164. Xbe run.  This was done for debugging.  The reported results are from a
  165. Xsingle run in which all loops were performed.
  166. X
  167. X\item All array references were converted from the 1 based subscript
  168. Xused by Fortran to 0 based subscripts as used by C.  This was done to
  169. Xavoid holes in the C arrays which would have resulted in different
  170. Xmemory use patterns.  This would have an occasional small adverse
  171. Ximpact on the C version, since some array references now involve
  172. Xsubtracting one from the indices.
  173. X
  174. X\end{itemize}
  175. X
  176. XA major change which wasn't made was transposing array indices.
  177. X
  178. X\section{Language Differences Encountered}
  179. X
  180. XThree major differences between Fortran and C were encountered which
  181. Xhave an impact on the transliteration.
  182. X
  183. X\begin{itemize}
  184. X
  185. X\item Different array index basis are used by the languages.  
  186. X\item Fortran uses \tt COMMON \rm blocks to allocate global data,
  187. Xwhile C merely requires declaring it.  
  188. X\item C and Fortran have different rules for arithmetic precision.  Some
  189. Xminor differences also exist.
  190. X
  191. X\end{itemize}
  192. X
  193. XEach of these will be discussed in turn.
  194. X
  195. XThe array index basis difference has two implications.  One of these is
  196. Xthe way in which indices relate to memory locations in multiple
  197. Xdimension arrays, and the other is the difference in array basing.
  198. XC arrays are always indexed from 0 to \tt N - 1 \rm where \tt N \rm is
  199. Xthe number of elements declared for that index of the array.  The
  200. Xdefault basing in Fortran is to index from 1 to \tt N, \rm although 0
  201. Xbasing is an option.  All of the arrays in the Livermore Loops are 1
  202. Xbased.  In the transliteration, this was explicitly adjusted for.  In
  203. Xthe main, this consists of adjusting loop indices to run from 0 to \tt
  204. XN - 1 \rm rather than from 1 to \tt N \rm and subtracting 1 from
  205. Xconstant indices as part of the transliteration.
  206. X
  207. XThis can also be a problem when integer values are calculated by a
  208. Xprogram and then used as loop indices.  An attempt was made to find
  209. Xall such places and convert them appropriately.  In a few cases, the
  210. Xcalculations were left alone, and 1 was subtracted when the integer
  211. Xvariable was used as a subscript.
  212. X
  213. XThe other difference in arrays has to do with multiple dimension
  214. Xarrays.  For example, the Fortran array
  215. X
  216. X\begin{verbatim}
  217. X      DIMENSION A(2,2)
  218. X\end{verbatim}
  219. X
  220. X\noindent
  221. Xis stored in ascending memory addresses as \tt A(1,1), A(2,1), A(1,2),
  222. XA(2,2) \rm from low address to high address.  The equivalent C array
  223. X
  224. X\begin{verbatim}
  225. X  float a[2][2];
  226. X\end{verbatim}
  227. X
  228. X\noindent
  229. Xis stored as \tt a[0][0], a[0][1], a[1][0], a[1][1] \rm from low
  230. Xaddress to high address.  A complete transliteration would transpose
  231. Xindices from left to right to preserve the actual memory ordering.
  232. XThis was not done in this transliteration.  Assuming that the original
  233. XFortran had been carefully coded for memory access, this would cause a
  234. Xdegradation of performance of the C code on some systems.
  235. X
  236. XThe Livermore Loops utilize the fairly common Fortran practice of
  237. Xincluding a number of related items together in a \tt COMMON \rm
  238. Xblock in order to make global references to those items possible.
  239. X
  240. XOne of the side effects of this practice is that Fortran requires that
  241. Xitems which are adjacently listed in a common block are adjacently
  242. Xallocated in memory.  This makes possible the practice of initializing
  243. Xan entire \tt COMMON \rm block by treating it as a single array in an
  244. Xinitialization routine.  Figure~1 shows an example in Fortran.
  245. X
  246. X\begin{figure}[ht]
  247. X\small
  248. X\caption{\tt COMMON \rm usage in Fortran}
  249. X\begin{verbatim}
  250. X
  251. XC
  252. XC THIS ROUTINE USES THREE ELEMENTS OF A COMMON BLOCK BY SOME NAME
  253. XC
  254. X      COMMON /CBLOCK/ A1, B1, C1
  255. X      SUBROUTINE AROUTINE
  256. XC
  257. XC USE A1, B1, C1
  258. XC
  259. X      RETURN
  260. X      END
  261. XC
  262. XC THIS ROUTINE INITIALIZES THE COMMON BLOCK USING AN ARRAY
  263. XC
  264. X      COMMON /CBLOCK/ A(3)
  265. X      SUBROUTINE INIT
  266. X      DO 10 I = 1, 3
  267. X   10 A(I) = I
  268. X      RETURN
  269. X      END
  270. X
  271. X\end{verbatim}
  272. X\end{figure}
  273. X
  274. XThe initialization routines in the Livermore Loops take advantage of
  275. Xthis.  There are several \tt COMMON \rm blocks, each of which contains
  276. Xmany arrays.  There is an initialization routine which treats each \tt
  277. XCOMMON \rm block as a single array, and initializes it in a single
  278. Xloop.
  279. X
  280. XIt is possible to duplicate the adjacent storage effect of \tt COMMON
  281. X\rm blocks in C.  Figure~2 shows an example of this usage.
  282. X
  283. X\begin{figure}[ht]
  284. X\small
  285. X\caption{Translating \tt COMMON \rm usage to C}
  286. X\begin{verbatim}
  287. X
  288. Xstruct cblock {
  289. X  float A_[3];
  290. X} CBLOCK;
  291. X
  292. X#define A1 CBLOCK.A_[0]
  293. X#define B1 CBLOCK.A_[1]
  294. X#define C1 CBLOCK.A_[2]
  295. X#define A  CBLOCK.A_
  296. X
  297. Xvoid init()
  298. X{
  299. X  int i;
  300. X  for (i = 0; i < 3; i++)
  301. X    A[i] = i;
  302. X}
  303. X
  304. Xmain()
  305. X{
  306. X  init();
  307. X  fprintf(stdout,"A1 = %f, B1 = %f, C1 = %f\n", A1, B1, C1);
  308. X}
  309. X
  310. X\end{verbatim}
  311. X\end{figure}
  312. X
  313. XIt is possible to use this technique within the \tt struct \rm to duplicate
  314. Xany possible naming which comes up within a \tt COMMON \rm block.  In
  315. Xparticular, multiple arrays can be implemented by using either unions
  316. Xand preprocessor defines, if they do not overlap, or names and
  317. Xpreprocessor macro functions if they do overlap.
  318. X
  319. XBecause the only uses of the \tt COMMON \rm blocks within the Livermore
  320. XLoops is to provide global data and to simplify initialization and
  321. Xchecksum calculation, this approach was not taken, but rather each
  322. Xvariable was declared as a C global, and the initialization routines
  323. Xwere modified to explicitly initialize each routine separately.  This
  324. Xhas an impact on both the initialization and checksum software.
  325. X
  326. XOn machines for which \tt double \rm provides more precision than \tt
  327. Xfloat \rm in C, numerical calculations are done differently in C than
  328. Xin Fortran.  When all of the variables involved in a calculation are
  329. Xof the same precision, Fortran calculates all intermediate results to
  330. Xthat precision.  C promotes all variable to the precision of \tt
  331. Xdouble, \rm does all calculations in double and converts to the
  332. Xprecision of the result.  This yields different numerical results when
  333. Xthere are subexpressions, for instance in the case
  334. X
  335. X\begin{verbatim}
  336. Xresult = a * b - c * d
  337. X\end{verbatim}
  338. X
  339. XFortran would calculate the two products, convert to the appropriate
  340. Xprecision, perform the addition and store the result.  C would
  341. Xcalculate the two products in \tt double \rm precision, perform a \tt
  342. Xdouble \rm precision add, and then convert the result.  This can yield
  343. Xquite different numbers.
  344. X
  345. XThe routine which generates the initial data was carefully coded to
  346. Xmimic Fortran conversion, so that the initial data would be the same
  347. Xin the C case as in the Fortran case, and care was taken to see that
  348. Xsubroutine calls were performed with the correct argument types, but
  349. Xthe test routines calculate the results using default C promotion
  350. Xrules.
  351. X
  352. X\section{Verifying the Transliteration}
  353. X
  354. XThe Convex compilers provide statement counting as a profiler option.
  355. XThe Fortran and C versions of the loops were run with no optimization
  356. Xand with statement profiling enabled.  The statement counts were
  357. Xcompared on a statement by statement basis for the two programs.  All
  358. Xloops were found to agree exactly.
  359. X
  360. XOnce the statement counts were completed, the two programs were run on
  361. Xthe Cray 2, which has the same precision for \tt float \rm and \tt
  362. Xdouble \rm in C.  The Fortran version was compiled with CFT77 release
  363. X3.0 with all optimization disabled.  The C version was compiled with
  364. Xthe UniCos 4.0 C compiler.
  365. X
  366. XLoops 1 through 5, 7, 11, 12, 13, 14, 16, 17, 20, and 24 produce
  367. Xidentical checksums to 12 decimal places, which is nearly the limit of
  368. Xfloating point precision on the Cray 2.  Loops 6, 8, 9, 10, 15, 18,
  369. X21 and 23 all match to at least five decimal places.  Careful
  370. Xinspection of the loops was made by running the Fortran and C versions
  371. Xsimultaneously under a source level debugger on a Silicon Graphics
  372. XIris 4D workstation.  Several additional bugs were corrected, but no
  373. Xdifference in the numerical results was found.  It is suspected that
  374. Xthe remaining differences are due to bugs in the way in which the
  375. Xchecksums are calculated under C.
  376. X
  377. X\section{Overview of Results}
  378. X
  379. XThe various tables show the reported megaflop rates for the C and Fortran
  380. Xversion of the Livermore Loops on several machines which were
  381. Xavailable to the author.  Of the machines which were available, the
  382. XIris and the Sun were chosen as representative of the current
  383. Xgeneration of engineering workstation, the Amdahl as representative of
  384. Xcurrent mainframes, the Convex and Alliant as representative of two
  385. Xdifferent approaches to minisupercomputers, and the Cray 2 as a
  386. Xrepresentative supercomputer.  All of the machines are running recent
  387. Xreleases of the vendor's version of the Unix operating system.
  388. X
  389. XFor all machines, the overall performance of the C compiler was better
  390. Xthan the overall performance of the Fortran compiler.  For the mainly
  391. XUnix systems, this was not surprising, but it was surprising on the
  392. XCray 2.  A detailed comparison of the optimizations done by the two
  393. XCray compilers on loops which were significantly different is
  394. Xpresented below.
  395. X
  396. X\begin{table}[htbp]
  397. X\caption{Results in Megaflops}
  398. X\small
  399. X\begin{tabular}{|r|rr|rr|rrr|} 
  400. X\hline
  401. X{\bf Manufacture} & \multicolumn{2}{|c|}{Alliant}  &
  402. X\multicolumn{2}{|c|}{Amdahl} & \multicolumn{3}{|c|}{Cray} \\
  403. X{\bf Model} & \multicolumn{2}{|c|}{FX/8} & \multicolumn{2}{|c|}{5880} &
  404. X\multicolumn{3}{|c|}{2} \\
  405. X{\bf Compiler} & cc & fortran & cc & f77 & cc (vector) & cft77 (vector) &
  406. Xcft77 (scalar) \\ 
  407. X\hline
  408. X1 & 10.72 & 15.02 & 15.02 & 1.88 & 764.77 & 96.89 & 13.53 \\
  409. X2 & 7.76 & 0.78 & 11.64 & 1.16 & 30.28 & 18.45 & 6.40 \\
  410. X3 & 7.51 & 1.00 & 15.02 & 1.72 & 21.39 & 69.57 & 11.29 \\
  411. X4 & 6.55 & 0.72 & 9.00 & 1.03 & 18.32 & 32.10 & 4.16 \\
  412. X5 & 7.06 & 0.71 & 12.00 & 1.09 & 20.36 & 9.85 & 10.67 \\
  413. X6 & 5.95 & 0.49 & 10.82 & 1.01 & 21.29 & 9.08 & 3.90 \\
  414. X7 & 15.92 & 19.10 & 18.73 & 2.51 & 929.28 & 147.31 & 16.35 \\
  415. X8 & 8.07 & 14.26 & 11.56 & 1.07 & 41.67 & 113.39 & 17.55 \\
  416. X9 & 14.72 & 10.30 & 25.75 & 1.72 & 748.91 & 113.07 & 13.88 \\
  417. X10 & 4.54 & 5.45 & 9.09 & 0.55 & 21.40 & 35.32 & 6.68 \\
  418. X11 & 4.29 & 0.43 & 7.50 & 0.75 & 11.00 & 9.02 & 7.57 \\
  419. X12 & 4.00 & 5.99 & 6.66 & 0.60 & 246.53 & 30.61 & 5.24 \\
  420. X13 & 1.68 & 0.27 & 4.48 & 0.24 & 6.44 & 1.75 & 1.66 \\
  421. X14 & 3.06 & 1.16 & 5.46 & 0.52 & 14.61 & 7.22 & 3.88 \\
  422. X15 & 5.29 & 2.54 & 5.86 & 0.63 & 23.05 & 6.94 & 6.66 \\
  423. X16 & 4.54 & 0.45 & 10.60 & 1.59 & 15.28 & 4.00 & 3.86 \\
  424. X17 & 7.79 & 1.82 & 13.63 & 2.73 & 36.74 & 8.08 & 7.81 \\
  425. X18 & 10.62 & 7.26 & 9.07 & 0.88 & 64.29 & 100.59 & 11.61 \\
  426. X19 & 7.27 & 0.73 & 12.12 & 1.21 & 27.08 & 12.40 & 11.34 \\
  427. X20 & 10.91 & 1.47 & 17.93 & 2.40 & 50.41 & 12.33 & 11.39 \\
  428. X21 & 7.13 & 1.82 & 6.07 & 0.60 & 15.16 & 23.43 & 6.13 \\
  429. X22 & 6.06 & 5.15 & 8.59 & 0.86 & 47.05 & 90.76 & 5.94 \\
  430. X23 & 7.10 & 0.93 & 9.33 & 0.91 & 30.69 & 9.41 & 8.99 \\
  431. X24 & 3.53 & 6.00 & 10.00 & 1.00 & 8.32 & 1.95 & 1.87 \\
  432. XHarmonic Mean & 5.59 & 1.09 & 9.37 & 0.87 & 22.38 & 9.26 & 5.7 \\
  433. X\hline
  434. X\end{tabular}
  435. X\end{table}
  436. X
  437. X
  438. X\begin{table}[htbp]
  439. X\caption{Results in Megaflops}
  440. X\small
  441. X\begin{tabular}{|r|rr|rr|rr|}
  442. X\hline
  443. X{\bf Manufacture} & \multicolumn{2}{|c|}{Convex} &
  444. X\multicolumn{2}{|c|}{Silicon Graphics} & \multicolumn{2}{|c|}{Sun} \\
  445. X{\bf Model} & \multicolumn{2}{|c|}{C1} & \multicolumn{2}{|c|}{Iris 4D}  &
  446. X\multicolumn{2}{|c|}{Sun 3/250} \\
  447. X{\bf Compiler} & vc & fc & Mips cc & Mips f77 & cc & f77 \\
  448. X\hline
  449. X1 & 1102.90 & 175.23 & 8.94 & 1.32 & 1.35 & 0.18 \\
  450. X2 & 8.49 & 1.57 & 7.76 & 1.29 & 1.11 & 0.12 \\
  451. X3 & 5.82 & 9.57 & 6.90 & 1.33 & 1.10 & 0.20 \\
  452. X4 & 7.37 & 1.34 & 6.00 & 0.71 & 0.99 & 0.11 \\
  453. X5 & 6.81 & 1.32 & 5.00 & 0.69 & 1.05 & 0.11 \\
  454. X6 & 4.16 & 3.80 & 5.67 & 0.86 & 0.97 & 0.12 \\
  455. X7 & 1811.50 & 331.52 & 13.38 & 1.75 & 1.93 & 0.18 \\
  456. X8 & 10.82 & 247.95 & 12.73 & 1.25 & 1.41 & 0.16     \\
  457. X9 & 1428.90 & 195.82 & 13.21 & 1.56 & 1.66 & 0.16 \\
  458. X10 & 2.57 & 7.15 & 8.26 & 0.91 & 0.74 & 0.09 \\
  459. X11 & 4.72 & 2.18 & 3.57 & 0.63 & 0.72 & 0.08 \\
  460. X12 & 2.55 & 16.34 & 3.57 & 0.62 & 0.75 & 0.08 \\
  461. X13 & 1.73 & 0.56 & 2.24 & 0.14 & 0.45 & 0.05 \\
  462. X14 & 4.24 & 1.34 & 4.27 & 0.37 & 0.73 & 0.08 \\
  463. X15 & 3.94 & 1.65 & 5.14 & 0.61 & 1.41 & 0.23 \\
  464. X16 & 5.18 & 0.88 & 7.57 & 0.88 & 1.18 & 0.17 \\
  465. X17 & 7.55 & 1.31 & 11.36 & 1.82 & 0.99 & 0.16 \\
  466. X18 & 8.50 & 11.38 & 9.99 & 1.12 & 1.35 & 0.16 \\
  467. X19 & 7.89 & 1.83 & 5.51 & 1.01 & 0.96 & 0.12 \\
  468. X20 & 7.17 & 1.60 & 10.83 & 1.42 & 1.72 & 0.25 \\
  469. X21 & 3.97 & 7.66 & 6.93 & 0.91 & 0.84 & 0.12 \\
  470. X22 & 5.60 & 101.18 & 6.87 & 0.90 & 1.94 & 0.32 \\
  471. X23 & 6.59 & 2.52 & 9.07 & 1.05 & 1.21 & 0.14 \\
  472. X24 & 90.46 & 9.16 & 4.35 & 0.63 & 1.13 & 0.14 \\
  473. XHarmonic Mean & 5.62 & 2.37 & 6.09 & 0.72 & 1.02 & 0.13 \\
  474. X\hline
  475. X\end{tabular}
  476. X\end{table}
  477. X
  478. X\section{Alliant Performance}
  479. X
  480. XThe Alliant Fortran compiler performs analysis to determine if a loop
  481. Xis vectorizable or can be executed concurrently on multiple
  482. Xprocessors.  If the loop can be executed concurrently and in vector
  483. Xmode, it tries to find a way to use both vectorization and
  484. Xconcurrently simultaneously.  The Alliant C compiler performs neither
  485. Xvectorization nor concurrency analysis and always produces scalar
  486. Xsingle processor code.  The Alliant Fortran compiler suffers from
  487. Xtrying to hard.  Sometimes it produces vector or concurrent code for
  488. Xwhich the overhead of the code exceeds the gain from the facility.  In
  489. Xthese case, such as loops 3, 9 and 13, the scalar C code performs more
  490. Xefficiently than the optimized Fortran code.  In other cases, such as
  491. Xloops 1 and 7, the Fortran code out performs the C code.  In no case
  492. Xdoes the optimization give a speedup of more than 2 over the scalar
  493. Xcode.
  494. X
  495. X\section{Amdahl Performance}
  496. X
  497. XThe Amdahl Fortran compiler is a straightforward port of the BSD Unix
  498. Xf77 compiler.  It does not appear to have been tuned to the Amdahl
  499. Xarchitecture at all and generates very poor code.  The Amdahl C
  500. Xcompiler is more tuned to the architecture and in some cases, Amdahl
  501. Xscalar code performance approaches that of the Cray 2. Because of the
  502. Xlarge difference between the compilers, a detailed comparison was not
  503. Xundertaken. 
  504. X
  505. X\section{Cray 2 Performance}
  506. X
  507. XThere are four loops (1, 7, 9, and 12) for which C achieves
  508. X``impossible'' performance on the Cray 2, as a result of exceeding the
  509. Xmaximum performance of a single processor.  These are the result of an
  510. Xartifact of the benchmark.  C outperforms the Fortran code on most
  511. Xscalar loops, (5, 11, 13, 16, 17, 19, 20, and 24) with one exception.
  512. X(22) Fortran recognizes more loops as vectorizable than C, and
  513. Xproduces  better performance on the one loop (18) which both compilers
  514. Xvectorize. There is mixed performance on those loops which Fortran
  515. Xvectorizes and C does not.  In some cases, (2, 6, 14, 15, and 23) the
  516. Xscalar C code is more efficient that the vector Fortran code. In the
  517. Xremaining cases (3, 4, 8 10 and  21) the vector Fortran code is more
  518. Xefficient than the scalar C code. 
  519. X
  520. XThe impossible performance of C is a result of an artifact of the
  521. Xbenchmarks. To obtain a large enough time interval for meaningful
  522. Xmeasurement, all of the loops are of the form:
  523. X
  524. X\begin{verbatim}
  525. X
  526. XFOR I = 1 TO NUMBER_OF_PASSES DO
  527. X  BEGIN
  528. X    do_the_loop_in_question
  529. X  END
  530. X
  531. X\end{verbatim}
  532. X
  533. XIn the impossible cases, the loop in question is of form similar to:
  534. X
  535. X\begin{verbatim}
  536. X
  537. XFOR J = 1 to ARRAY_LENGTH DO
  538. X  BEGIN
  539. X    X[J] := Y[J] op Z[J];
  540. X  END
  541. X
  542. X\end{verbatim}
  543. X
  544. XIn this very simple case, it is possible for a reasonable compiler to
  545. Xdetermine that the entire inner loop is invariant with respect to the
  546. Xouter loop, move the inner loop outside the outer loop, and then throw
  547. Xthe outer loop away because it doesn't compute anything.  If the
  548. Xvariable on the left side of the equation never appears on the right
  549. Xside, the loop is invariant and can be collapsed.  Close inspection
  550. Xshows that the performance advantage of C on Loops 1, 7, 9, and 12 can
  551. Xbe explained as a result of this optimization of the outer loop.  The
  552. XFortran compiler misses this optimization.
  553. X
  554. XThe original Fortran version of Loop 2 contains a compiler directive
  555. Xto force vectorization.  The C version does not force vectorization,
  556. Xbut instead produces scalar code.  Further, the vector length is 101,
  557. Xwhich is fairly short compared to the overhead introduced by setting
  558. Xup the vector loop.  C produces faster code for this case, as a result
  559. Xof not vectorizing the loop.  Loop 6 shows a similar phenomena.  In
  560. Xthis case, Fortran recognizes a conditional dependency and generates
  561. Xcode to use vector instructions when it doesn't occur. Again the
  562. Xoverhead is not justified and the C version is faster.  This also
  563. Xhappens in loops 14 and 23. 
  564. X
  565. XIn other cases, the Fortran compiler vectorizes and the C compiler
  566. Xdoes not and the Fortran code code runs faster than the C code.  The
  567. Xperformance improvement varies between 1.5 and 3.2 times.
  568. X
  569. XIn all but one of the cases in which both languages generate scalar
  570. Xcode, C generates more efficient code than Fortran.  The exception is
  571. Xloops 22.  Fortran generates  inline code for the \tt exp \rm
  572. Xfunction, while C generates calls to a subroutine.  Although current C
  573. Xcompilers don't usually generate inline code, the ANSI draft standard
  574. Xprovides a mechanism for defining and implementing inlines, and some
  575. Xcompilers do support the mechanism.
  576. X
  577. XOn the Cray 2, C generates shorter less convoluted loops and uses more
  578. Xregister\footnote{Actually, local memory, which C treats as a large
  579. Xregister file.} references than Fortran.  Overall, this appears to
  580. Xgive C a scalar performance advantage over Fortran.  Compiling the
  581. XFortran loops with vectorization disabled shows C scalar performance
  582. Xto vary from 2 to 5 times faster than Fortran scalar performance.
  583. X
  584. X\section{Convex Performance}
  585. X
  586. XThe Convex compilers produce considerable documentation of their
  587. Xactions.  Figure~3 shows part of the vectorization summary from the C
  588. Xcompiler for the file containing the loops.  The Convex compiler
  589. Xrecognizes a wide range of language constructs, including goto driven
  590. Xloops as potential for vectorization.  It is able to realize in some
  591. Xcases that it should not vectorize a loop and frequently able to give
  592. Xgood information about why a loop cannot be vectorized.
  593. X
  594. X\begin{figure}[ht]
  595. X\small
  596. X\caption{Vectorization using Convex C}
  597. X\begin{verbatim}
  598. X
  599. XSource Iter.                                 Vector-       
  600. XLine   Var.         Start     Stop     Step  ization     Reason
  601. X---------------------------------------------------------------------------
  602. X   42  k           *EXPR*    ipntp        2  None  Not enough vector code
  603. X   53  k           *EXPR*        n        1  PART  Vector (50%)
  604. X   99  ky          *EXPR*        n        1  FULL  Vector
  605. X  149  l           *EXPR*       lp        1  None  Unable to distribute
  606. X  167  ip          *EXPR*        n        1  PART  Vector (92%)
  607. X  213  l           *EXPR*       lp        1  None  Not trip counted
  608. X  266  k           *EXPR*        n        1  None  Inner loop: exit
  609. X  329  l           *EXPR*       lp        1  None  Inner loop: unknown trips
  610. X
  611. X\end{verbatim}
  612. X\end{figure}
  613. X
  614. XBoth the Convex C and Fortran compilers recognized the same loops as
  615. Xvectorizable for the same reasons, except for loop 22, which Fortran
  616. Xrecognized and 24, which C recognized.  The compiler which recognized
  617. Xa loop as vectorizable produced much faster code.  If both compilers
  618. Xproduced scalar code or both produced vector code, the C compiler
  619. Xproduced more efficient code.  The C compiler appears to do a better
  620. Xjob of managing register allocation and memory references and so
  621. Xproduces code with less memory bandwidth requirements.
  622. X
  623. X\section{Silicon Graphics Performance}
  624. X
  625. XThe Silicon Graphics Iris 4D uses a MIPS R2000\cite{Kane87} RISC
  626. Xprocessor chip set, with a floating point accelerator.  RISC
  627. XArchitecture machines depend heavily on compiler technology to
  628. Xgenerate efficient code in all cases, and it is not surprising that the
  629. XMIPS machine performs well.  That Fortran did not fare as well as C
  630. Xcan be attributed to the primary market place of the Iris, which uses
  631. XC as its major programming language.  It appears that more effort has
  632. Xgone into C compiler than has gone into the Fortran compiler.
  633. X
  634. X\section{Sun 3 Performance}
  635. X
  636. XThe Sun 3 numbers show a classic example of difference in code
  637. Xgeneration quality.  Sun has spent a lot of time on the C compiler,
  638. Xwhich is the mainstay of their product and not as much time on the
  639. XFortran compiler.  As a result, the C compiler produces more efficient
  640. Xcode than the Fortran compiler in all cases.
  641. X
  642. X\section{Conclusions}
  643. X
  644. XThese results demonstrate that on certain machines, using certain
  645. Xcompiler implementations, it is possible for a C compiler to produce
  646. Xmore efficient code than a Fortran compiler for a specific numerical
  647. Xapplication.   Which compiler generates more efficient code appears to
  648. Xdepend more on the maturity of the compiler than on the nature of the
  649. Xmachine. From the way in which the loops were transliterated, it is
  650. Xsafe to say that it is possible to write C code which can be easily
  651. Xoptimized, as it is possible to write Fortran code which can be easily
  652. Xoptimized.
  653. X
  654. XThis is not to say that C has all of the features which make Fortran a
  655. Xgood choice for numerical calculation.  An informal poll of numerical
  656. Xprogrammers who are familiar with both Fortran and C produced a
  657. Xpartial list of features seen to be important which are not present in
  658. Xthe C language.  The list included the integer exponentiation operator,
  659. Xautomatic dimensioning of parameter arrays, complex numbers and
  660. Xthe repeat count in formatted i/o.  Dynamic memory allocation and
  661. Xpointers were viewed as an advantage of C over Fortran.
  662. X
  663. XCurrent compiler technology is making it more difficult to develop
  664. Xreasonable benchmarks which measure what they intend to measure.
  665. XAlthough the Livermore Loops have held up well over time, they are
  666. Xstarting to fall to optimizing compilers.  In particular, the ability
  667. Xto detect invariance of the outer loop has led to invalid results
  668. Xbeing returned for particular loops.
  669. X
  670. XAs McMahon pointed out, performance can be as much a factor of the
  671. Xmaturity of compiler technology as of the machine on which the code
  672. Xruns.  This is as true for codes written in C as it is for Fortran.
  673. XIt is also true for the relative performance of various compilers from
  674. Xthe same vendor on a given machine.
  675. X
  676. XIt is possible to ``overoptimize.''  Vector operations include some
  677. Xoverhead, such as pipeline start up, which must be accounted for by
  678. Xthe optimizer.  Concurrent operations also introduce overhead.  Some
  679. Xcompilers are more sophisticated about this than others.  The Convex
  680. Xcompiler will not vectorize a loop if it believes that there is
  681. Xinsufficient code to benefit.
  682. X
  683. XSome vendors appear to have paid more attention to vector optimization
  684. Xin their Fortran compilers than to scalar, although many of these
  685. Xloops could benefit from scalar optimization.  This is most apparent
  686. Xin the difference between C and Fortran scalar performance on the Cray 2.
  687. X
  688. XIt is possible to write numerical codes in C and have them compiled
  689. Xinto efficient code which produces correct results.  Any code which can
  690. Xbe written in Fortran can also be written in C to produce the same
  691. Xresults, and a good C compiler can generate efficient results from the
  692. Xspecified code.
  693. X
  694. X\bibliography{unix,misc}
  695. X\bibliographystyle{plain}
  696. X
  697. X\end{document}
  698. END_OF_FILE
  699. if test 28304 -ne `wc -c <'cloops.tex'`; then
  700.     echo shar: \"'cloops.tex'\" unpacked with wrong size!
  701. fi
  702. # end of 'cloops.tex'
  703. fi
  704. echo shar: End of archive 3 \(of 3\).
  705. cp /dev/null ark3isdone
  706. MISSING=""
  707. for I in 1 2 3 ; do
  708.     if test ! -f ark${I}isdone ; then
  709.     MISSING="${MISSING} ${I}"
  710.     fi
  711. done
  712. if test "${MISSING}" = "" ; then
  713.     echo You have unpacked all 3 archives.
  714.     rm -f ark[1-9]isdone
  715. else
  716.     echo You still need to unpack the following archives:
  717.     echo "        " ${MISSING}
  718. fi
  719. ##  End of shell archive.
  720. exit 0
  721.  
  722. exit 0 # Just in case...
  723.